package com.situ.tos2024.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.tos2024.dao.OrderDAO;
import com.situ.tos2024.model.Order;
import com.situ.tos2024.model.User;
import com.situ.tos2024.service.OrderService;
import com.situ.tos2024.util.PaginateInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    private OrderDAO orderDAO;

    @Autowired
    public void setOrderDAO(OrderDAO orderDAO) {
        this.orderDAO = orderDAO;
    }

    @Override
    public List<Order> findAll(PaginateInfo pi, Order search) {
        //自动分页插件的操作
        //1.启动分页
        try (Page<?> p = PageHelper.startPage(pi.getPageNo(), pi.getPageSize());) {
            //2.正常进行查询
            List<Order> orders = orderDAO.findAll(search);

            //3.获取分页数据
            PageInfo<Order> pif = new PageInfo<>(orders);
            //pif.calcByNavigatePages(10);//根据导航页共10页进行计算
            pi.setPageInfo(pif);//将分页对象缓存

            return orders;
        }
    }
}
